% 珠峰学报文档类

\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{zhufeng}[2019/12/08 Journal of Zhufeng 2019a]
\typeout{Journal of Zhufeng (version: 2019 Autumn)}

% 是否整合书稿，默认为单篇文章的草稿
\newif\if@final
\newif\if@ebook
\DeclareOption{final}{\@finaltrue}
\DeclareOption{ebook}{\@ebooktrue}
\ProcessOptions

% 字体设置
\usepackage[heading]{ctex}
\setmainfont[Scale=1.1]{Libertinus Serif}
\setsansfont[Scale=1.1]{Libertinus Sans}
\RequirePackage[heading]{ctex}\RequirePackage{amsmath,amssymb}
\RequirePackage{unicode-math}
\setmathfont{Cambria Math}
\setmathfont[version=bold,FakeBold=3.5]{Cambria Math}
\let\oldtextbf=\textbf
\renewcommand\textbf[1]{{\boldmath\oldtextbf{#1}}}

% 页面板式
\RequirePackage{geometry}
\if@ebook
  \geometry{
    paper      = b6paper,
    vmargin    = 2cm,
    hmargin    = 1cm,
    headheight = 0.75cm,
    headsep    = 0.15cm,
  }
\else
  \geometry{
    paper      = a4paper,
    vmargin    = 2.25cm,
    hmargin    = 2cm,
    headheight = 0.75cm,
    headsep    = 0.15cm,
    columnsep  = 0.75cm,
  }
\fi
\savegeometry{L1}  % 供首页以外页面使用

% 图表标号
\renewcommand{\thefigure}{\arabic{figure}}
\renewcommand{\thetable}{\arabic{table}}
\renewcommand{\theequation}{\arabic{equation}}

% 数学样式
\RequirePackage{amsthm}
\newtheoremstyle{note}{1ex}{1ex}{\sffamily}{-\parindent}{\sffamily}{.}{.5em}{}
\newtheoremstyle{myplain}{1ex}{1ex}{}{-\parindent}{}{.}{.5em}{}
\theoremstyle{note}
\newtheorem{definition}{\hskip 1.88em\bfseries 定义\hskip 0.1em}[chapter]
\newtheorem{theorem}{\hskip 1.88em\bfseries 定理\hskip 0.1em}[chapter]
\newtheorem{proposition}[theorem]{\hskip 1.88em\bfseries 命题\hskip 0.1em }
\newtheorem{property}[theorem]{\hskip 1.88em\bfseries 性质\hskip 0.1em }
\newtheorem{lemma}[theorem]{\hskip 1.88em\bfseries 引理\hskip 0.1em }
\newtheorem{corollary}[theorem]{\hskip 1.88em\bfseries 推论\hskip 0.1em }
\newtheorem{conjecture}{\hskip 1.88em\bfseries 猜想\hskip 0.1em }[chapter]
\theoremstyle{myplain}
\newtheorem{example}{\hskip 1.88em\bfseries 例\hskip 0.1em}[chapter]
\newtheorem{problem}{\hskip 1.88em\bfseries 问题\hskip 0.1em}[chapter]
\newtheorem*{remark}{\hskip 1.88em\bfseries 附注\hskip 0.1em }
\renewcommand{\thedefinition}{\arabic{definition}}
\renewcommand{\thetheorem}{\arabic{theorem}}
\renewcommand{\theproposition}{\arabic{proposition}}
\renewcommand{\thelemma}{\arabic{lemma}}
\renewcommand{\thecorollary}{\arabic{corollary}}
\renewcommand{\theconjecture}{\arabic{conjecture}}
\RequirePackage{siunitx}

% 正文排版样式
\ziju{.05pt}
\setlength{\columnseprule}{0pt}
\RequirePackage{caption}
\if@ebook
  \newenvironment{multicols}[1]{}{}  % 忽视所有 mutlicols 环境
\else
  \RequirePackage{multicol}
\fi
\captionsetup{hypcap=false}
\setcounter{tocdepth}{0}
\RequirePackage[shortlabels]{enumitem}

% 脚注样式
\renewcommand{\thefootnote}{\textbf{(\arabic{footnote})}}

% 图表样式
\RequirePackage{graphicx}
\RequirePackage{float}
\RequirePackage{subcaption}
\newenvironment{Figure}
  {\par\medskip\noindent\minipage{\linewidth}}
  {\endminipage\par\medskip}
\setlength{\intextsep}{1ex plus 2pt}
\RequirePackage{booktabs,longtable}
\RequirePackage{tabularx}
\RequirePackage{multirow}

% 标题样式
\RequirePackage{xcolor}
\RequirePackage[most]{tcolorbox}
\ctexset{
  subsubsection/beforeskip = .5ex plus .2ex,
  subsubsection/afterskip = 0pt,
  subsection/beforeskip = 1ex plus .2ex,
  subsection/afterskip = 0pt,
  section/beforeskip = 1.5ex plus .2ex,
  section/afterskip = 0pt,
  paragraph/beforeskip = 0pt,
  paragraph/afterskip = 1em,}
\RequirePackage[explicit]{titlesec}
\titleformat{\section}{\Large\bfseries}%
{\begin{tcolorbox}[notitle, boxrule=0pt, colframe=white, colback=black!10]%
\parbox{\dimexpr\linewidth-2\fboxsep\relax}{\centering\arabic{section}\ #1}%
\end{tcolorbox}}{0pt}{}
\titleformat{name=\section, numberless}{\Large\bfseries}%
{\begin{tcolorbox}[notitle, boxrule=0pt, colframe=white, colback=black!10]%
\parbox{\dimexpr\linewidth-2\fboxsep\relax}{\centering#1}\end{tcolorbox}}%
{0pt}{}
\titleformat{\subsection}{\large\bfseries}%
{\parbox{\linewidth}{\arabic{section}.\arabic{subsection}
#1\vspace{1ex}}}{0pt}{}
\titleformat{name=\subsection, numberless}{\large\bfseries}%
{\parbox{\linewidth}{#1\vspace{1ex}}}{0pt}{}
\titleformat{name=\subsubsection, numberless}{\large\itshape}%
{\parbox{\linewidth}{#1\vspace{1ex}}}{0pt}{}

% 默认元信息
\newcommand{\@fancyheader}{}
\newcommand{\@subtitle}{}
\newcommand{\subtitle}[1]{\gdef\@subtitle{#1}}
\newcommand{\@issue}{}
\newcommand{\issue}[1]{\gdef\@issue{#1}}
\newcommand{\@publisher}{}
\newcommand{\publisher}[1]{\gdef\@publisher{#1}}
\newcommand{\@wallpaper}{}
\newcommand{\@wallpaperscale}{}
\newcommand{\wallpaper}[2][1]{\def\@wallpaperscale{#1}%
  \def\@wallpaper{#2}}


% 页眉页脚样式
\RequirePackage{fancyhdr}
\RequirePackage{pgfornament}
\fancyhead[L,R]{}
\fancyhead[C]{\large\color{gray}\itshape\@fancyheader}
\fancyfoot[C]{\color{gray}\thepage\\[-5pt]\pgfornament[scale=.25]{82}}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\headrule}{\vspace{-.4em}\hbox to\headwidth{\color{lightgray}%
\leaders\hrule height \headrulewidth\hfill}}
\ctexset{chapter/pagestyle = fancy}
\pagestyle{fancy}

% 文章标题样式定义
\newcommand{\authortoc}{\theauthor}
\RequirePackage{titling}
\RequirePackage{wallpaper}
\RequirePackage{tikz}
\newcommand{\passagetitle}[1][\clearpage]{
  #1\refstepcounter{chapter}\null
  \begin{center}
  {\bfseries\huge\thetitle}\par
  \ifx{\@subtitle}{}{}\else{\vskip2ex\large\@subtitle}\fi\vskip2ex
  {\ctexset{space=true}\Large\itshape\theauthor}
  \end{center}
  {\ctexset{space=true}\addcontentsline{toc}{chapter}%
  {\thetitle （\authortoc）}}
  \setcounter{section}{0}
  \setcounter{figure}{0}
  \setcounter{table}{0}
  \setcounter{equation}{0}
  \setcounter{footnote}{0}
  \subtitle{}}  % for future use

% 首页重定义
\if@final
\renewcommand{\maketitle}{
  \pdfbookmark{封面}{titlepage}
  \thispagestyle{empty}
  \newgeometry{margin = 0pt}
  \ThisCenterWallPaper{\@wallpaperscale}{\@wallpaper}
  %\null\vskip10ex
  \begin{tcolorbox}[notitle, colback=white, opacityback=0.5,
      enhanced jigsaw, left=40pt, right=40pt, top=40pt, bottom=40pt,
      boxrule=0pt, arc=0pt]
  \hfill\parbox[c]{0.5\textwidth}{\centering
  {\if@ebook\fontsize{2.75em}{1ex}\else\fontsize{4.5em}{1ex}\fi\bfseries\thetitle}\\[2ex]
  {\scshape\if@ebook\fontsize{1.25em}{1ex}\else\fontsize{2em}{1ex}\fi\selectfont\@subtitle}\\[4ex]
  {\sffamily\if@ebook\fontsize{1.25em}{1ex}\else\fontsize{2em}{1ex}\fi\selectfont \@issue}\\[1.5ex]
  {\itshape\if@ebook\fontsize{1.25em}{1ex}\else\fontsize{2em}{1ex}\fi\@publisher\ 发行}
  }
  \end{tcolorbox}
  {\pagestyle{empty}\pagenumbering{roman}\clearpage}
  \loadgeometry{L1}}
\else
\renewcommand{\maketitle}{\passagetitle}
\fi

% 目录样式修改
\RequirePackage{tocloft}
\renewcommand{\cftchapfont}{\large\itshape}
\tocloftpagestyle{empty}
\renewcommand{\cfttoctitlefont}{\Huge\bfseries\centerline}
\renewcommand{\cftaftertoctitle}{\centerline{\pgfornament[scale=.3]{85}}}
\renewcommand{\cftchappagefont}{\normalfont}
\cftpagenumbersoff{part}
\renewcommand{\cftpartfont}{\Large\bfseries\,}
\renewcommand{\cftpartafterpnum}{\\[-1.5ex]\hbox to\textwidth{\color{lightgray}%
\leaders\hrule height \headrulewidth\hfill}}

% 扉页刊物信息定义
\newcommand{\infocontent}{}  % 左侧栏目信息
\newcommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\newcommand{\infotitle}[1]{\centerline{\large\bfseries #1}}
\newcommand{\makeinfo}{
  \if@ebook
  \begin{tcolorbox}[breakable, notitle, boxrule=0pt, colframe=white, colback=black!10]
  \else
  \begin{tcolorbox}[notitle, boxrule=0pt, colframe=white, colback=black!10, left skip=-10pt]
  \fi
  \null\infocontent
  \end{tcolorbox}}

% 生成扉页
\newcommand{\bottombox}{}
\newcommand{\makepreface}{
  {\clearpage\pagenumbering{arabic}\setcounter{page}{1}
  \pagestyle{empty}\null
  \pdfbookmark{扉页}{preface}
  \if@ebook
    \makeinfo\clearpage\tableofcontents
  \else
    \begin{minipage}{.4\textwidth}
    \makeinfo
    \end{minipage}
    \hspace{1em}
    \begin{minipage}{.5\textwidth}
    \tableofcontents
    \vspace{10ex}
    \end{minipage}
  \fi
  \vfil\bottombox
  \clearpage}
  \subtitle{}  % for future use
  \renewcommand{\maketitle}{\passagetitle}}

% 摘要环境定义
\renewcommand{\abstractname}{摘要}
\newenvironment{abstract}{
  \begin{tcolorbox}[title=\abstractname, fonttitle=\bfseries\large,boxrule=1pt,%
  colframe=black!20, colback=white, coltitle=black, breakable]}%
  {\end{tcolorbox}}
\newcommand{\keyword}{
  \par\vskip.25em
  \ctexset{space=true}
  \textbf{关键词：}\itshape}

% 参考文献样式修正
\RequirePackage{etoolbox}
\patchcmd{\thebibliography}{\chapter*}{\section*}{}{}

% 作者信息栏目
\newenvironment{authorinfo}%
{\begin{tcolorbox}[title={作者信息}, colback=white, colframe=black!20, boxrule=1pt, fonttitle=\bfseries\small, coltitle=black, breakable]\small}%
{\end{tcolorbox}}

% 板块划分命令
\newcommand{\journalpart}[1]{
  \refstepcounter{part}
  \addcontentsline{toc}{part}{#1}}

% 超链接设置
\RequirePackage{hyperref}
\PassOptionsToPackage{hyphens}{url}
\AtBeginDocument{\hypersetup{
  hidelinks,
  pageanchor = true,
  pdftitle = \thetitle （\@issue ）,
  pdfauthor = \theauthor,
  pdfsubject = \thetitle,
  pdfkeywords = {\thetitle, \theauthor, 刊物},
  pdfview = {XYZ null null 1},
  pdfcreator = {Zhufeng LaTeX template}}
\xdef\@fancyheader{\@subtitle}}

% 此宏包必须在最后引用
\if@final\RequirePackage{subfiles}\fi

\endinput
